package task

import android.view.View
import android.widget.Button
import event.TakeButtonClickEvent
import manager.TaskManager
import org.greenrobot.eventbus.EventBus

class TakeButtonCtrlTask (val button: Button) : Runnable, View.OnClickListener {

    companion object {
        private val Timeout = 60 * 1000L
    }

    init {
        button.setOnClickListener(this)
    }

    override fun onClick(v: View?) {
        EventBus.getDefault().post( TakeButtonClickEvent() )
        hide()
    }

    fun hide() {
        TaskManager.UiHandler.removeCallbacks(this)
        button.visibility = View.INVISIBLE
    }

    fun show() {
        TaskManager.UiHandler.removeCallbacks(this)
        button.visibility = View.VISIBLE
    }

    fun hideWithDuration() {
        TaskManager.UiHandler.postDelayed(this, Timeout)
    }

    override fun run() {
        hide()
    }
}